package com.wanghua.spring.filter.upload;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

/*
* Filter 与 Listener 都属于 Servlet 的规范。
* 文件上传Filter。
* 众所周知，上传文件需要把form表单的enctype设为"multipart/form-data"。而默认的request不能处理这种multipart的表单，执行
* request.getParameter(filename)只能得到null。
* 下面来自定义一个request，使的 request.getParameter(filename) 可以获取上传的文件。
* */
public class UploadFilter implements Filter {
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		UploadRequestWrapper uploadRequest = new UploadRequestWrapper((HttpServletRequest) request);
		chain.doFilter(uploadRequest, response);
	}

	public void init(FilterConfig config) throws ServletException {
	}

	public void destroy() {
	}
}
